package com.sicheng.lc.周赛.分类.排列组合计数;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/7/2 14:49
 */
public class 分隔长廊的方案数 {
    //https://leetcode.cn/problems/number-of-ways-to-divide-a-long-corridor/
    public int numberOfWays(String corridor) {
        if(corridor.length() <= 1)
            return 0;
        long res = 1;
        int mod = (int) (1e9 + 7);
        int count = 0;
        int last = -1;
        for (int i = 0; i < corridor.length(); i++) {
            if (corridor.charAt(i) == 'S') {
                count = count + 1;
                if (count % 2 == 0) {
                    last = i;
                } else if (last != -1) {
                    res = res * (i - last) % mod;
                }
            }
        }
        if (count == 0 || count % 2 != 0) {
            return 0;
        }
        return (int) res;
    }

    public static void main(String[] args) {
        分隔长廊的方案数 s = new 分隔长廊的方案数();
        int res = s.numberOfWays("PPSPSP");
        System.out.println(res);
    }
}
